﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;

namespace Project
{
    public partial class advisorProfile : System.Web.UI.Page
    {
        static string connectionString = ConfigurationManager.ConnectionStrings["StudentAdvisorString"].ConnectionString;
        SqlConnection connection = new SqlConnection(connectionString);
        SqlCommand command_profile = null;
        SqlCommand command_update = null;
        SqlDataReader dataReader = null;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["userID"] == null)
                Response.Redirect("Default.aspx");
            else
                lbl_username.Text = "Welcome, " + Session["userID"].ToString();

            string profile_string = "select * from advisorinfo where AdvisorId='" + Session["userID"].ToString() + "'";
            command_profile = new SqlCommand(profile_string, connection);
            try
            {
                connection.Open();
                dataReader = command_profile.ExecuteReader();
                dataReader.Read();
                txt_firstName.Text = dataReader[1].ToString();
                txt_lastName.Text = dataReader[2].ToString();
                txt_email.Text = dataReader[3].ToString();
                txt_emailS.Text = dataReader[4].ToString();
                txt_phoneExtension.Text = dataReader[5].ToString();

            }
            catch (SqlException ex)
            {
            }
            finally
            {
                if (!dataReader.IsClosed)
                {
                    dataReader.Close();
                    connection.Close();
                }
            }
            txt_firstName.Enabled = false;
            txt_lastName.Enabled = false;
            txt_email.Enabled = false;
            txt_emailS.Enabled = false;
            txt_phoneExtension.Enabled = false;

        }

        protected void btn_logout_Click(object sender, EventArgs e)
        {
            Session["userID"] = null;
            Session["userType"] = null;
            Response.Redirect("Default.aspx");
        }

        //protected void btn_edit_update_Click(object sender, EventArgs e)
        //{
        //    if (btn_edit_update.Text == "Edit")
        //    {
        //        txt_firstName.Enabled = true;
        //        txt_lastName.Enabled = true;
        //        txt_email.Enabled = true;
        //        txt_emailS.Enabled = true;
        //        txt_phoneExtension.Enabled = true;
        //        btn_edit_update.Text = "Update";
        //    }
        //    else
        //    {
        //        string update_string = "update tblAdvisorInfo set AdvisorFirstName='" + txt_firstName.Text + "',AdivisorLastName='" + txt_lastName.Text + "',EmailPrimary='" + txt_email.Text + "',EmailSecondary='" + txt_emailS.Text + "',PhoneExtension='" + txt_phoneExtension.Text + "' where AdvisortId='" + Session["userID"].ToString() + "'";
        //        command_update = new SqlCommand(update_string, connection);

        //        try
        //        {
        //            connection.Open();
        //            command_update.ExecuteNonQuery();
        //            connection.Close();
        //            lbl_update.Text = "Your profile has been updated...";
        //        }
        //        catch (SqlException ex)
        //        {
        //            lbl_update.Text = ex.ToString();
        //        }
        //        finally
        //        {

        //        }
        //        btn_edit_update.Text = "Edit";
        //    }
        //}
    }
}